import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class ATSolution {

	Scanner in;

	PrintWriter out;

	int dp[][];

	int ar[];

	int gen(int i, int diff) {
		diff = Math.abs(diff);
		if (i == ar.length) {
			if (diff == 0) {
				return 0;
			} else {
				return Integer.MAX_VALUE / 2;
			}
		}
		if (dp[i][diff] != -1) {
			return dp[i][diff];
		}
		int ans = gen(i + 1, diff + ar[i]);
		ans = Math.min(gen(i + 1, diff - ar[i]), ans);
		ans = Math.min(gen(i + 1, diff) + ar[i], ans);
		dp[i][diff] = ans;
		return ans;
	}

	void solve() {
		ar = new int[in.nextInt()];
		int sum = 0;
		for (int i = 0; i < ar.length; i++) {
			ar[i] = in.nextInt();
			sum += ar[i];
		}
		dp = new int[ar.length][sum + 1];
		for (int a[] : dp) {
			Arrays.fill(a, -1);
		}
		out.println(gen(0, 0));

	}

	void run() {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		try {
			solve();
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new ATSolution().run();
	}
}
